﻿namespace UnityEditor
{
    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Runtime.CompilerServices;
    using System.Runtime.InteropServices;
    using UnityEditor.Utils;
    using UnityEditorInternal;
    using UnityEngine;

    [CustomEditor(typeof(Material)), CanEditMultipleObjects]
    internal class MaterialEditor : Editor
    {
        [CompilerGenerated]
        private static Dictionary<string, int> <>f__switch$map14;
        public int lightMode = 1;
        protected bool m_AllowRotation = true;
        protected ShaderUtil.ShaderPropertyTexDim m_DesiredTexdim;
        private string m_InfoMessage;
        protected bool m_IsVisible;
        private PreviewRenderUtility m_PreviewUtility;
        private SerializedProperty m_Shader;
        public Vector2 previewDir = new Vector2(0f, -20f);
        private static GUIContent[] s_LightIcons = new GUIContent[2];
        private static Mesh[] s_Meshes = new Mesh[4];
        private static GUIContent[] s_MeshIcons = new GUIContent[4];
        public int selectedMesh;

        public virtual void Awake()
        {
            this.m_IsVisible = InternalEditorUtility.GetIsInspectorExpanded(base.target);
        }

        protected void DoRenderPreview()
        {
            if ((this.m_PreviewUtility.m_RenderTexture.width > 0) && (this.m_PreviewUtility.m_RenderTexture.height > 0))
            {
                Color color;
                this.m_PreviewUtility.m_Camera.transform.position = (Vector3) (-Vector3.forward * 5f);
                this.m_PreviewUtility.m_Camera.transform.rotation = Quaternion.identity;
                if (this.lightMode == 0)
                {
                    this.m_PreviewUtility.m_Light[0].intensity = 0.5f;
                    this.m_PreviewUtility.m_Light[0].transform.rotation = Quaternion.Euler(30f, 30f, 0f);
                    this.m_PreviewUtility.m_Light[1].intensity = 0f;
                    color = new Color(0.2f, 0.2f, 0.2f, 0f);
                }
                else
                {
                    this.m_PreviewUtility.m_Light[0].intensity = 0.5f;
                    this.m_PreviewUtility.m_Light[0].transform.rotation = Quaternion.Euler(50f, 50f, 0f);
                    this.m_PreviewUtility.m_Light[1].intensity = 0.5f;
                    color = new Color(0.2f, 0.2f, 0.2f, 0f);
                }
                InternalEditorUtility.SetCustomLighting(this.m_PreviewUtility.m_Light, color);
                this.m_PreviewUtility.DrawMesh(s_Meshes[this.selectedMesh], Vector3.zero, Quaternion.Euler(this.previewDir.y, 0f, 0f) * Quaternion.Euler(0f, this.previewDir.x, 0f), base.target as Material, 0);
                bool fog = RenderSettings.fog;
                Unsupported.SetRenderSettingsUseFogNoDirty(false);
                this.m_PreviewUtility.m_Camera.Render();
                Unsupported.SetRenderSettingsUseFogNoDirty(fog);
                InternalEditorUtility.RemoveCustomLighting();
            }
        }

        private Color GetColor(string propertyName, out bool hasMixedValue)
        {
            hasMixedValue = false;
            Color color = (base.targets[0] as Material).GetColor(propertyName);
            for (int i = 1; i < base.targets.Length; i++)
            {
                if ((base.targets[i] as Material).GetColor(propertyName) != color)
                {
                    hasMixedValue = true;
                    return color;
                }
            }
            return color;
        }

        private float GetFloat(string propertyName, out bool hasMixedValue)
        {
            hasMixedValue = false;
            float @float = (base.targets[0] as Material).GetFloat(propertyName);
            for (int i = 1; i < base.targets.Length; i++)
            {
                if ((base.targets[i] as Material).GetFloat(propertyName) != @float)
                {
                    hasMixedValue = true;
                    return @float;
                }
            }
            return @float;
        }

        private Texture GetTexture(string propertyName, out bool hasMixedValue)
        {
            hasMixedValue = false;
            Texture texture = (base.targets[0] as Material).GetTexture(propertyName);
            for (int i = 1; i < base.targets.Length; i++)
            {
                if ((base.targets[i] as Material).GetTexture(propertyName) != texture)
                {
                    hasMixedValue = true;
                    return texture;
                }
            }
            return texture;
        }

        private Vector2 GetTextureOffset(string propertyName, out bool hasMixedValueX, out bool hasMixedValueY)
        {
            hasMixedValueX = false;
            hasMixedValueY = false;
            Vector2 textureOffset = (base.targets[0] as Material).GetTextureOffset(propertyName);
            for (int i = 1; i < base.targets.Length; i++)
            {
                Vector2 vector2 = (base.targets[i] as Material).GetTextureOffset(propertyName);
                if (vector2.x != textureOffset.x)
                {
                    hasMixedValueX = true;
                }
                if (vector2.y != textureOffset.y)
                {
                    hasMixedValueY = true;
                }
                if (hasMixedValueX && hasMixedValueY)
                {
                    return textureOffset;
                }
            }
            return textureOffset;
        }

        private Vector2 GetTextureScale(string propertyName, out bool hasMixedValueX, out bool hasMixedValueY)
        {
            hasMixedValueX = false;
            hasMixedValueY = false;
            Vector2 textureScale = (base.targets[0] as Material).GetTextureScale(propertyName);
            for (int i = 1; i < base.targets.Length; i++)
            {
                Vector2 vector2 = (base.targets[i] as Material).GetTextureScale(propertyName);
                if (vector2.x != textureScale.x)
                {
                    hasMixedValueX = true;
                }
                if (vector2.y != textureScale.y)
                {
                    hasMixedValueY = true;
                }
                if (hasMixedValueX && hasMixedValueY)
                {
                    return textureScale;
                }
            }
            return textureScale;
        }

        private Vector4 GetVector(string propertyName, out bool hasMixedValue)
        {
            hasMixedValue = false;
            Vector4 vector = (base.targets[0] as Material).GetVector(propertyName);
            for (int i = 1; i < base.targets.Length; i++)
            {
                if ((base.targets[i] as Material).GetVector(propertyName) != vector)
                {
                    hasMixedValue = true;
                    return vector;
                }
            }
            return vector;
        }

        public override bool HasPreviewGUI()
        {
            return true;
        }

        private void Init()
        {
            if (this.m_PreviewUtility == null)
            {
                this.m_PreviewUtility = new PreviewRenderUtility();
            }
            if (s_Meshes[0] == null)
            {
                GameObject obj2 = (GameObject) EditorGUIUtility.LoadRequired("Previews/PreviewMaterials.fbx");
                obj2.SetActive(false);
                IEnumerator enumerator = obj2.transform.GetEnumerator();
                try
                {
                    while (enumerator.MoveNext())
                    {
                        Transform current = (Transform) enumerator.Current;
                        string name = current.name;
                        if (name != null)
                        {
                            int num;
                            if (<>f__switch$map14 == null)
                            {
                                Dictionary<string, int> dictionary = new Dictionary<string, int>(4);
                                dictionary.Add("sphere", 0);
                                dictionary.Add("cube", 1);
                                dictionary.Add("cylinder", 2);
                                dictionary.Add("torus", 3);
                                <>f__switch$map14 = dictionary;
                            }
                            if (<>f__switch$map14.TryGetValue(name, out num))
                            {
                                switch (num)
                                {
                                    case 0:
                                    {
                                        s_Meshes[0] = ((MeshFilter) current.GetComponent("MeshFilter")).sharedMesh;
                                        continue;
                                    }
                                    case 1:
                                    {
                                        s_Meshes[1] = ((MeshFilter) current.GetComponent("MeshFilter")).sharedMesh;
                                        continue;
                                    }
                                    case 2:
                                    {
                                        s_Meshes[2] = ((MeshFilter) current.GetComponent("MeshFilter")).sharedMesh;
                                        continue;
                                    }
                                    case 3:
                                    {
                                        s_Meshes[3] = ((MeshFilter) current.GetComponent("MeshFilter")).sharedMesh;
                                        continue;
                                    }
                                }
                            }
                        }
                        Debug.Log("Something is wrong, weird object found: " + current.name);
                    }
                }
                finally
                {
                    IDisposable disposable = enumerator as IDisposable;
                    if (disposable == null)
                    {
                    }
                    disposable.Dispose();
                }
                s_MeshIcons[0] = EditorGUIUtility.IconContent("PreMatSphere");
                s_MeshIcons[1] = EditorGUIUtility.IconContent("PreMatCube");
                s_MeshIcons[2] = EditorGUIUtility.IconContent("PreMatCylinder");
                s_MeshIcons[3] = EditorGUIUtility.IconContent("PreMatTorus");
                s_LightIcons[0] = EditorGUIUtility.IconContent("PreMatLight0");
                s_LightIcons[1] = EditorGUIUtility.IconContent("PreMatLight1");
            }
        }

        internal override void OnAssetStoreInspectorGUI()
        {
            this.OnInspectorGUI();
        }

        public virtual void OnDisable()
        {
            if (this.m_PreviewUtility != null)
            {
                this.m_PreviewUtility.Cleanup();
                this.m_PreviewUtility = null;
            }
            EditorApplication.undoRedoPerformed = (EditorApplication.CallbackFunction) Delegate.Remove(EditorApplication.undoRedoPerformed, new EditorApplication.CallbackFunction(this.UndoRedoPerformed));
        }

        public virtual void OnEnable()
        {
            this.m_Shader = base.serializedObject.FindProperty("m_Shader");
            EditorApplication.undoRedoPerformed = (EditorApplication.CallbackFunction) Delegate.Combine(EditorApplication.undoRedoPerformed, new EditorApplication.CallbackFunction(this.UndoRedoPerformed));
            this.PropertiesChanged();
        }

        internal override void OnHeaderControlsGUI()
        {
            base.serializedObject.Update();
            EditorGUI.BeginDisabledGroup(!this.IsEnabled());
            EditorGUIUtility.LookLikeControls(50f);
            this.ShaderPopup("MiniPulldown");
            if ((!this.m_Shader.hasMultipleDifferentValues && (this.m_Shader.objectReferenceValue != null)) && ((this.m_Shader.objectReferenceValue.hideFlags & HideFlags.DontSave) == 0))
            {
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.ExpandWidth(false) };
                if (GUILayout.Button("Edit...", EditorStyles.miniButton, options))
                {
                    AssetDatabase.OpenAsset(this.m_Shader.objectReferenceValue);
                }
            }
            EditorGUI.EndDisabledGroup();
        }

        internal override void OnHeaderGUI()
        {
            Rect position = Editor.DrawHeaderGUI(this, this.targetName);
            bool isExpanded = EditorGUI.DoObjectFoldout(GUIUtility.GetControlID(0xb26e, FocusType.Passive), position, base.targets, this.m_IsVisible);
            if (isExpanded != this.m_IsVisible)
            {
                this.m_IsVisible = isExpanded;
                InternalEditorUtility.SetIsInspectorExpanded(base.target, isExpanded);
            }
        }

        public override void OnInspectorGUI()
        {
            base.serializedObject.Update();
            if ((this.m_IsVisible && !this.m_Shader.hasMultipleDifferentValues) && ((this.m_Shader.objectReferenceValue != null) && this.PropertiesGUI()))
            {
                this.PropertiesChanged();
            }
        }

        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                if (Event.current.type == EventType.Repaint)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 40f), "Material preview \nnot available");
                }
            }
            else
            {
                this.Init();
                if (this.m_AllowRotation)
                {
                    this.previewDir = PreviewGUI.Drag2D(this.previewDir, r);
                }
                if (Event.current.type == EventType.Repaint)
                {
                    this.m_PreviewUtility.BeginPreview(r, background);
                    this.DoRenderPreview();
                    Texture image = this.m_PreviewUtility.EndPreview();
                    GUI.DrawTexture(r, image, ScaleMode.StretchToFill, false);
                }
            }
        }

        public override void OnPreviewSettings()
        {
            if (ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                this.Init();
                this.selectedMesh = PreviewGUI.CycleButton(this.selectedMesh, s_MeshIcons);
                this.lightMode = PreviewGUI.CycleButton(this.lightMode, s_LightIcons);
            }
        }

        public void OnSceneDrag()
        {
            Event current = Event.current;
            if (current.type != EventType.Repaint)
            {
                GameObject obj2 = HandleUtility.PickGameObject(current.mousePosition, false);
                if (((obj2 == null) ? 0 : obj2.renderer) != null)
                {
                    switch (current.type)
                    {
                        case EventType.DragUpdated:
                            DragAndDrop.visualMode = DragAndDropVisualMode.Copy;
                            Undo.RegisterUndo(obj2.renderer, "Set Material");
                            obj2.renderer.sharedMaterial = base.target as Material;
                            current.Use();
                            break;

                        case EventType.DragPerform:
                            DragAndDrop.AcceptDrag();
                            Undo.RegisterUndo(obj2.renderer, "Set Material");
                            obj2.renderer.sharedMaterial = base.target as Material;
                            current.Use();
                            break;
                    }
                }
            }
        }

        protected void OnSelectedShaderPopup(string command, Shader shader)
        {
            base.serializedObject.Update();
            if (shader != null)
            {
                this.m_Shader.objectReferenceValue = shader;
                base.serializedObject.ApplyModifiedProperties();
                Undo.RegisterUndo(base.targets, "Assign Shader to " + this.targetName, 1);
                foreach (Material material in base.targets)
                {
                    material.shader = shader;
                }
            }
            this.PropertiesChanged();
        }

        protected void PropertiesChanged()
        {
            this.m_InfoMessage = null;
            if (base.targets.Length == 1)
            {
                this.m_InfoMessage = PerformanceChecks.CheckMaterial(base.target as Material, EditorUserBuildSettings.activeBuildTarget);
            }
        }

        public bool PropertiesGUI()
        {
            float num = 64f;
            EditorGUIUtility.LookLikeControls((Screen.width - num) - 20f);
            EditorGUI.BeginChangeCheck();
            Shader objectReferenceValue = this.m_Shader.objectReferenceValue as Shader;
            GUILayoutOption option = GUILayout.Width(10f);
            GUILayoutOption option2 = GUILayout.MinWidth(32f);
            bool hasMixedValue = false;
            for (int i = 0; i < ShaderUtil.GetPropertyCount(objectReferenceValue); i++)
            {
                object[] objArray1;
                float num3;
                float num4;
                float num5;
                bool flag2;
                Material material;
                UnityEngine.Object[] targets;
                int num7;
                UnityEngine.Object[] objArray2;
                System.Type type;
                if (ShaderUtil.IsShaderPropertyHidden(objectReferenceValue, i))
                {
                    continue;
                }
                string propertyDescription = ShaderUtil.GetPropertyDescription(objectReferenceValue, i);
                string propertyName = ShaderUtil.GetPropertyName(objectReferenceValue, i);
                switch (ShaderUtil.GetPropertyType(objectReferenceValue, i))
                {
                    case ShaderUtil.ShaderPropertyType.Color:
                    {
                        EditorGUI.BeginChangeCheck();
                        Color color = this.GetColor(propertyName, out hasMixedValue);
                        EditorGUI.showMixedValue = hasMixedValue;
                        color = EditorGUILayout.ColorField(propertyDescription, color, new GUILayoutOption[0]);
                        EditorGUI.showMixedValue = false;
                        if (EditorGUI.EndChangeCheck())
                        {
                            this.RegisterPropertyChangeUndo(propertyDescription);
                            this.SetColor(propertyName, color);
                        }
                        continue;
                    }
                    case ShaderUtil.ShaderPropertyType.Vector:
                    {
                        EditorGUI.BeginChangeCheck();
                        Vector4 vector3 = this.GetVector(propertyName, out hasMixedValue);
                        EditorGUI.showMixedValue = hasMixedValue;
                        vector3 = EditorGUILayout.Vector4Field(propertyDescription, vector3, new GUILayoutOption[0]);
                        EditorGUI.showMixedValue = false;
                        if (EditorGUI.EndChangeCheck())
                        {
                            this.RegisterPropertyChangeUndo(propertyDescription);
                            this.SetVector(propertyName, vector3);
                        }
                        continue;
                    }
                    case ShaderUtil.ShaderPropertyType.Float:
                    {
                        EditorGUI.BeginChangeCheck();
                        float @float = this.GetFloat(propertyName, out hasMixedValue);
                        EditorGUI.showMixedValue = hasMixedValue;
                        @float = EditorGUILayout.FloatField(propertyDescription, @float, new GUILayoutOption[0]);
                        EditorGUI.showMixedValue = false;
                        if (EditorGUI.EndChangeCheck())
                        {
                            this.RegisterPropertyChangeUndo(propertyDescription);
                            this.SetFloat(propertyName, @float);
                        }
                        continue;
                    }
                    case ShaderUtil.ShaderPropertyType.Range:
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        num3 = ShaderUtil.GetRangeLimits(objectReferenceValue, i, 1);
                        num4 = ShaderUtil.GetRangeLimits(objectReferenceValue, i, 2);
                        EditorGUILayout.PrefixLabel(propertyDescription, "HorizontalSlider");
                        EditorGUI.BeginChangeCheck();
                        num5 = this.GetFloat(propertyName, out hasMixedValue);
                        EditorGUI.showMixedValue = hasMixedValue;
                        if (!(propertyName == "_Shininess"))
                        {
                            break;
                        }
                        num5 = EditorGUILayout.PowerSlider(num5, num3, num4, 5f, new GUILayoutOption[0]);
                        goto Label_012B;

                    case ShaderUtil.ShaderPropertyType.TexEnv:
                        if (!(base.target is ProceduralMaterial))
                        {
                            goto Label_0262;
                        }
                        flag2 = false;
                        targets = base.targets;
                        num7 = 0;
                        goto Label_024B;

                    default:
                        goto Label_0766;
                }
                num5 = GUILayout.HorizontalSlider(num5, num3, num4, new GUILayoutOption[0]);
            Label_012B:
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    this.RegisterPropertyChangeUndo(propertyDescription);
                    this.SetFloat(propertyName, num5);
                }
                GUILayout.EndHorizontal();
                continue;
            Label_021A:
                material = (Material) targets[num7];
                if (SubstanceImporter.IsProceduralTextureSlot(material, material.GetTexture(propertyName), propertyName))
                {
                    flag2 = true;
                    goto Label_0256;
                }
                num7++;
            Label_024B:
                if (num7 < targets.Length)
                {
                    goto Label_021A;
                }
            Label_0256:
                if (flag2)
                {
                    continue;
                }
            Label_0262:
                objArray2 = base.targets;
                for (int j = 0; j < objArray2.Length; j++)
                {
                    Material mat = (Material) objArray2[j];
                    ShaderUtil.CheckNoTexturePropertyAndRebuild(mat, objectReferenceValue, i);
                }
                this.m_DesiredTexdim = ShaderUtil.GetTexDim(objectReferenceValue, i);
                switch (this.m_DesiredTexdim)
                {
                    case ShaderUtil.ShaderPropertyTexDim.TexDim2D:
                        type = typeof(Texture);
                        break;

                    case ShaderUtil.ShaderPropertyTexDim.TexDim3D:
                        type = typeof(Texture3D);
                        break;

                    case ShaderUtil.ShaderPropertyTexDim.TexDimCUBE:
                        type = typeof(Cubemap);
                        break;

                    case ShaderUtil.ShaderPropertyTexDim.TexDimRECT:
                        type = typeof(Texture);
                        break;

                    case ShaderUtil.ShaderPropertyTexDim.TexDimAny:
                        type = typeof(Texture);
                        break;

                    default:
                        type = null;
                        break;
                }
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                bool[] flagArray = new bool[2];
                bool[] flagArray2 = new bool[2];
                GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Width(20f) };
                EditorGUILayout.BeginVertical(options);
                EditorGUILayout.PrefixLabel(propertyDescription, EditorStyles.objectField);
                GUILayout.Space(3f);
                Vector2 vector = this.GetTextureScale(propertyName, out flagArray[0], out flagArray[1]);
                Vector2 vector2 = this.GetTextureOffset(propertyName, out flagArray2[0], out flagArray2[1]);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                GUILayout.Space(16f);
                GUILayout.FlexibleSpace();
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                GUILayoutOption[] optionArray2 = new GUILayoutOption[] { option };
                GUILayout.Label(string.Empty, EditorStyles.miniLabel, optionArray2);
                GUILayoutOption[] optionArray3 = new GUILayoutOption[] { option };
                GUILayout.Label("x", EditorStyles.miniLabel, optionArray3);
                GUILayoutOption[] optionArray4 = new GUILayoutOption[] { option };
                GUILayout.Label("y", EditorStyles.miniLabel, optionArray4);
                GUILayout.EndVertical();
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                GUILayout.Label("Tiling", EditorStyles.miniLabel, new GUILayoutOption[0]);
                for (int k = 0; k < 2; k++)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.showMixedValue = flagArray[k];
                    GUILayoutOption[] optionArray5 = new GUILayoutOption[] { option2 };
                    vector[k] = EditorGUILayout.FloatField(vector[k], EditorStyles.miniTextField, optionArray5);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.RegisterPropertyChangeUndo(propertyDescription);
                        this.SetTextureScale(propertyName, vector, k);
                    }
                }
                GUILayout.EndVertical();
                GUILayout.BeginVertical(new GUILayoutOption[0]);
                GUILayout.Label("Offset", EditorStyles.miniLabel, new GUILayoutOption[0]);
                for (int m = 0; m < 2; m++)
                {
                    EditorGUI.BeginChangeCheck();
                    EditorGUI.showMixedValue = flagArray2[m];
                    GUILayoutOption[] optionArray6 = new GUILayoutOption[] { option2 };
                    vector2[m] = EditorGUILayout.FloatField(vector2[m], EditorStyles.miniTextField, optionArray6);
                    if (EditorGUI.EndChangeCheck())
                    {
                        this.RegisterPropertyChangeUndo(propertyDescription);
                        this.SetTextureOffset(propertyName, vector2, m);
                    }
                }
                GUILayout.EndVertical();
                GUILayout.EndHorizontal();
                GUILayout.EndVertical();
                bool enabled = GUI.enabled;
                if (AnimationUtility.InAnimationMode())
                {
                    GUI.enabled = false;
                }
                EditorGUI.BeginChangeCheck();
                Texture texture = this.GetTexture(propertyName, out hasMixedValue);
                EditorGUI.showMixedValue = hasMixedValue;
                Rect aspectRect = GUILayoutUtility.GetAspectRect(1f);
                texture = EditorGUI.DoObjectField(aspectRect, aspectRect, EditorGUI.GetControlID(0x3042, EditorGUIUtility.native, aspectRect), texture, type, null, new EditorGUI.ObjectFieldValidator(this.TextureValidator), false) as Texture;
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    this.RegisterPropertyChangeUndo(propertyDescription);
                    this.SetTexture(propertyName, texture);
                }
                GUI.enabled = enabled;
                GUILayout.Space(6f);
                GUILayout.EndHorizontal();
                if (propertyName == "_BumpMap")
                {
                    bool flag4 = false;
                    foreach (Material material3 in base.targets)
                    {
                        if (InternalEditorUtility.BumpMapTextureNeedsFixing(material3))
                        {
                            flag4 = true;
                        }
                    }
                    if (flag4)
                    {
                        GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                        GUILayout.Space(16f);
                        GUILayout.BeginHorizontal(EditorStyles.helpBox, new GUILayoutOption[0]);
                        GUILayout.Label(EditorGUIUtility.TextContent("MaterialInspector.BumpMapFixingWarning"), EditorStyles.wordWrappedMiniLabel, new GUILayoutOption[0]);
                        GUILayout.FlexibleSpace();
                        GUILayout.BeginVertical(new GUILayoutOption[0]);
                        GUILayout.Space(5f);
                        if (GUILayout.Button(EditorGUIUtility.TextContent("MaterialInspector.BumpMapFixingButton"), new GUILayoutOption[0]))
                        {
                            foreach (Material material4 in base.targets)
                            {
                                if (InternalEditorUtility.BumpMapTextureNeedsFixing(material4))
                                {
                                    InternalEditorUtility.FixNormalmapTexture(material4);
                                }
                            }
                        }
                        GUILayout.EndVertical();
                        GUILayout.EndHorizontal();
                        GUILayout.EndHorizontal();
                    }
                }
                GUILayout.Space(6f);
                continue;
            Label_0766:
                objArray1 = new object[] { "Unknown property type ", propertyDescription, " : ", ShaderUtil.GetPropertyType(objectReferenceValue, i) };
                GUILayout.Label(string.Concat(objArray1), new GUILayoutOption[0]);
            }
            if (this.m_InfoMessage != null)
            {
                EditorGUILayout.HelpBox(this.m_InfoMessage, MessageType.Info);
            }
            return EditorGUI.EndChangeCheck();
        }

        private void RegisterPropertyChangeUndo(string label)
        {
            Undo.RegisterUndo(base.target, base.targets, "Modify " + label + " of " + this.targetName);
        }

        public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return null;
            }
            this.Init();
            this.m_PreviewUtility.BeginStaticPreview(new Rect(0f, 0f, (float) width, (float) height));
            this.DoRenderPreview();
            return this.m_PreviewUtility.EndStaticPreview();
        }

        private void SetColor(string propertyName, Color value)
        {
            foreach (Material material in base.targets)
            {
                material.SetColor(propertyName, value);
            }
        }

        private void SetFloat(string propertyName, float value)
        {
            foreach (Material material in base.targets)
            {
                material.SetFloat(propertyName, value);
            }
        }

        private void SetTexture(string propertyName, Texture value)
        {
            foreach (Material material in base.targets)
            {
                material.SetTexture(propertyName, value);
            }
        }

        private void SetTextureOffset(string propertyName, Vector2 value, int coord)
        {
            foreach (Material material in base.targets)
            {
                Vector2 textureOffset = material.GetTextureOffset(propertyName);
                textureOffset[coord] = value[coord];
                material.SetTextureOffset(propertyName, textureOffset);
            }
        }

        private void SetTextureScale(string propertyName, Vector2 value, int coord)
        {
            foreach (Material material in base.targets)
            {
                Vector2 textureScale = material.GetTextureScale(propertyName);
                textureScale[coord] = value[coord];
                material.SetTextureScale(propertyName, textureScale);
            }
        }

        private void SetVector(string propertyName, Vector4 value)
        {
            foreach (Material material in base.targets)
            {
                material.SetVector(propertyName, value);
            }
        }

        protected void ShaderPopup(GUIStyle style)
        {
            bool enabled = GUI.enabled;
            if (AnimationUtility.InAnimationMode())
            {
                GUI.enabled = false;
            }
            Shader objectReferenceValue = this.m_Shader.objectReferenceValue as Shader;
            Rect position = EditorGUI.PrefixLabel(EditorGUILayout.GetControlRect(new GUILayoutOption[0]), 0xb919, EditorGUIUtility.TempContent("Shader"));
            EditorGUI.showMixedValue = this.m_Shader.hasMultipleDifferentValues;
            GUIContent content = EditorGUIUtility.TempContent((objectReferenceValue == null) ? "No Shader Selected" : objectReferenceValue.name);
            if (EditorGUI.ButtonMouseDown(position, content, EditorGUIUtility.native, style))
            {
                EditorGUI.showMixedValue = false;
                Vector2 vector = GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.y));
                InternalEditorUtility.SetupShaderMenu(base.target as Material);
                EditorUtility.Internal_DisplayPopupMenu(new Rect(vector.x, vector.y, position.width, position.height), "CONTEXT/ShaderPopup", this, 0);
                Event.current.Use();
            }
            EditorGUI.showMixedValue = false;
            GUI.enabled = enabled;
        }

        private UnityEngine.Object TextureValidator(UnityEngine.Object[] references, System.Type objType, SerializedProperty property)
        {
            foreach (UnityEngine.Object obj2 in references)
            {
                Texture t = obj2 as Texture;
                if ((t != null) && ((ShaderUtil.GetTextureDimension(t) == this.m_DesiredTexdim) || (this.m_DesiredTexdim == ShaderUtil.ShaderPropertyTexDim.TexDimAny)))
                {
                    return t;
                }
            }
            return null;
        }

        public virtual void UndoRedoPerformed()
        {
            this.PropertiesChanged();
        }
    }
}

